package com.ebupt.migu.fineoperationactivitymonitor.common.entity;

import com.google.gson.Gson;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @author liuzz
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class ResultObject<T> {

    /**
     * 返回编码
     **/
    private String code = "0000";
    /**
     * 返回信息
     **/
    private String msg;
    /**
     * 数据
     */
    private T data;

    /**
     * to Json
     *
     * @return
     */
    public String toJson() {
        Gson gson = new Gson();
        return gson.toJson(this);
    }

    public ResultObject success() {
        return new ResultObject();
    }

    public ResultObject success(String msg) {
        ResultObject res = new ResultObject();
        res.setMsg(msg);
        return res;
    }

    public ResultObject success(String msg, Object data) {
        ResultObject res = new ResultObject();
        res.setMsg(msg);
        res.setData(data);
        return res;
    }
}
